/*
 * @Author: LiuYan
 * @Date: 2022-12-21 09:06:00
 * @LastEditors: LiuYan
 * @LastEditTime: 2023-01-04 09:48:30
 * @Description: 获取form中所有的值
 */
export default class PropsForm {
  constructor({ el }) {
    this._el = el;
    this.form = {};
    this.recursive(this._el.childNodes);
  }
  recursive(tags) {
    tags.forEach((tag) => {
      if (
        tag.getAttribute &&
        tag.getAttribute("prop") &&
        (tag.tagName == "TEXTAREA" || tag.tagName == "INPUT")
      ) {
        if (tag.getAttribute("type") == "checkbox") {
          this.form[tag.getAttribute("prop")] = tag.checked;
        } else if (tag.getAttribute("type") == "radio") {
          if (tag.checked) this.form[tag.getAttribute("prop")] = tag.value;
        } else {
          this.form[tag.getAttribute("prop")] = tag.value;
        }
      }
      if (tag.childNodes && tag.childNodes.length > 0) {
        this.recursive(tag.childNodes);
      }
    });
  }
}
